package com.qiyu.wakaka.common.utils.sms;

import com.yunpian.sdk.YunpianClient;
import com.yunpian.sdk.model.Result;
import com.yunpian.sdk.model.SmsSingleSend;

import java.util.Map;

/**
 * 云片网短信工具
 * @Auther: bear
 * @Date: 2019/5/5 19:17
 * @Description:
 */
public class YunSmsUtil {
    private static String UTF8 = "UTF-8";

    private static String APIKEY = "d55944049ab1304d507042446c149938";

    /**
     * 发送核销码短信
     * @param phone 手机号
     * @param name 购买套餐标题
     * @param url 生成的核销二维码地址
     */
    public static void senOrderSms(String phone,String name,String url){
        //初始化clnt,使用单例方式
        YunpianClient clnt = new YunpianClient(APIKEY).init();

        //发送短信API
        Map<String, String> param = clnt.newParam(2);
        param.put(YunpianClient.MOBILE, phone);
        StringBuffer sb = new StringBuffer();
        sb.append("【乐游虎丘】尊敬的游客，您已成功购买 ").append(name)
        .append(" ，点击此链接获取您的核销二维码 ").append(url).append("  登陆\"乐游虎丘\"微信小程序，领取免费美食券");
        param.put(YunpianClient.TEXT, sb.toString());
        Result<SmsSingleSend> r = clnt.sms().single_send(param);
        //获取返回结果，返回码:r.getCode(),返回码描述:r.getMsg(),API结果:r.getData(),其他说明:r.getDetail(),调用异常:r.getThrowable()

        //账户:clnt.user().* 签名:clnt.sign().* 模版:clnt.tpl().* 短信:clnt.sms().* 语音:clnt.voice().* 流量:clnt.flow().* 隐私通话:clnt.call().*

        //释放clnt
        clnt.close();
        System.out.println(r.toString());
    }

    /**
     * 发送提现状态告知短信
     * @param phone
     * @param name
     * @param status
     */
    public static void senBeniSms(String phone,String name,String status){
        //初始化clnt,使用单例方式
        YunpianClient clnt = new YunpianClient(APIKEY).init();

        //发送短信API
        Map<String, String> param = clnt.newParam(2);
        param.put(YunpianClient.MOBILE, phone);
        StringBuffer sb = new StringBuffer();
        sb.append("【乐游虎丘】尊敬的 ").append(name)
                .append(" ，您的提现申请已").append(status).append(" 感谢您的辛勤付出！祝您工作愉快！如您有任何疑问，请联系客服咨询:0571-88622693");
        param.put(YunpianClient.TEXT, sb.toString());
        Result<SmsSingleSend> r = clnt.sms().single_send(param);
        //获取返回结果，返回码:r.getCode(),返回码描述:r.getMsg(),API结果:r.getData(),其他说明:r.getDetail(),调用异常:r.getThrowable()

        //账户:clnt.user().* 签名:clnt.sign().* 模版:clnt.tpl().* 短信:clnt.sms().* 语音:clnt.voice().* 流量:clnt.flow().* 隐私通话:clnt.call().*

        //释放clnt
        clnt.close();
        System.out.println(r.toString());
    }

    public static void main(String[] args) {
//        senOrderSms("15658800821","虎丘山景区门票3人","https://cdn.321kaka.cn/QrPics/1557057384805.jpg");
        senBeniSms("15658800821","大雄","经提交，审核后会短信通知！");
        senBeniSms("15658800821","大雄","审核通过，稍后可在支付宝查看到账情况。");
        senBeniSms("15658800821","大雄","被拒绝退回！");
    }
}
